package cz.acies.face;

import java.util.List;

import com.google.gson.Gson;

import cz.acies.data.persist.TreeNode;

public class Tree extends Widget
{
	private static final long serialVersionUID = -4715555775150298334L;
	
	protected List<TreeNode> items;

	/*** Methods ***/
	protected String onSelect;
	
	public Tree() {
		super();
	}

	public Tree(String id, Widget parent) {
		super(id, parent);
	}

	public Tree(Widget parent) {
		super(parent);
	}

	@Override
	public String toHtml() {
		Gson gson = new Gson();
		String html = 
		"<ul id=\"folderTree\" class=\"easyui-tree\"></ul>" + 
		"<script type=\"text/javascript\">" + 
			"$(\"#"+this.id+"\").tree({" + 
				/*
				"onContextMenu: function(e, node){" + 
					"e.preventDefault();" + 
					"$(\"#"+this.id+"\").tree(\"select\", node.target);" + 
					"$(\"#foldersCtxMenu\").menu(\"show\", {" + 
						"left: e.pageX," + 
						"top: e.pageY" + 
					"});" + 
				"}," + 
				"onSelect: function(node){" + 
					"if (node.attributes.selectable) {" + 
						"var countryCode = node.id;" + 
					"}" + 
				"};" +
				*/ 
				"data: "+gson.toJson(getItems())+"" + 
			"});" + 
		"</script>"; 

		return html;
	}

	private void makeMethods() {
		
	}
	public List<TreeNode> getItems() {
		return items;
	}

	public void setItems(List<TreeNode> items) {
		this.items = items;
	}

	
}
